//
//  main.m
//  指针／链表
//
//  Created by apple on 15/7/27.
//  Copyright (c) 2015年 戴维营. All rights reserved.

#import <Foundation/Foundation.h>
        
//类型，通知系统如何分配内存空间

struct Student {
    char name [20];
    int age;
    float height,weight;
 
    struct Student *next;//(1)用指针 nest 存储student的地址
};
        
typedef struct Student Student;//(3)用student 来代替struct student以达到简化的目的

int main(int argc, const char * argv[]) {
    @autoreleasepool {
    
        NSLog(@"行: %d", arc4random_uniform(5) + 1);   // (4).[0,5)之间取随机数
        NSLog(@"列: %d", arc4random_uniform(8) + 1);
        
        NSLog(@"rand: %u",arc4random()%10);//(5)// (0,2^32-1)之间取随机值
    
        Student *pHead;//(2).
        Student stu0;
        stu0.age = 111;
        pHead = &stu0;
        
        Student stu1;
        stu1.age = 222;
        stu1.next = NULL;
        stu0.next = &stu1;
    
        Student stu2;
        stu2.age = 333;
        stu2.next = NULL;
        stu1.next = &stu2;
        
        //stu0 > stu2
        pHead->next = pHead->next->next;
        NSLog(@"%d",pHead->next->age);
        
       /* Student stu3;
        stu3.age = 444;
        stu3.next = pHead;
        
        //stuo > stu3 > stu2
        //stu3 > stu2
        
        stu3.next = pHead->next;
        //stu0 > stu3 >stu2
        pHead->next = &stu3;
        
        NSLog(@"pHead->age: %d",pHead->age);
        NSLog(@"pHead->next->age: %d",pHead->next->age);
        NSLog(@"pHead->next->next->age: %d",pHead->next->next->age);*/
        
     /*   NSLog(@"----------------");
        Student *pointer = pHead;
        //遍历链表
        while (pointer)
        {
            NSLog(@"age: %d",pointer->age);
            pointer = pointer->next;
        }
       // NSLog(@"(*((*(*pHead).next)).next)).age");
        
    //链表
    //1.有序
    //2.内存中不一定排列在一起
        NSLog(@"%p",pHead->next->next);
        
        return 0;
        
        NSLog(@"%zu",sizeof(struct Student));
        struct Student student;
        
        strcpy(student.name, "Zhangsan");
        student.age = 12;
        student.height = 1.5;
        student.weight = 60;
        
        NSLog(@"%s",student.name);
        NSLog(@"%d",student.age);
        
        struct Student student1;
        student1 = student;
        NSLog(@"%s",student1.name);
        NSLog(@"%d",student1.age);
        
        char name1[20] = "lisi";
        char name2[20];
        //name1 = name2
        strcpy(name2, name1);
        NSLog(@"%s",name2);
        
        Student *pStu =&student;
        NSLog(@"%s",(*pStu).name);
        NSLog(@"%s",pStu->name);*/
    }
    
    return 0;
}

    
        
        
    
